package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.PrizeDrawActivityPoolSettleLog;
import com.sc.nft.mapper.PrizeDrawActivityPoolSettleLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 瓜分活动-奖池累计记录表(sc_prize_draw_activity_pool_settle_log)数据DAO
 *
 * @author Sun
 * @since 2023-09-15 15:03:59
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class PrizeDrawActivityPoolSettleLogDao extends ServiceImpl<PrizeDrawActivityPoolSettleLogMapper, PrizeDrawActivityPoolSettleLog> {

    public List<PrizeDrawActivityPoolSettleLog> getPoolSettleLogList() {
        LambdaQueryWrapper<PrizeDrawActivityPoolSettleLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PrizeDrawActivityPoolSettleLog::getIsSettle, Boolean.FALSE);
        wrapper.last("limit 100");
        return this.list(wrapper);
    }

    public Boolean updateIssettleById(Long id) {
        LambdaUpdateWrapper<PrizeDrawActivityPoolSettleLog> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(PrizeDrawActivityPoolSettleLog::getId, id);
        wrapper.set(PrizeDrawActivityPoolSettleLog::getIsSettle, Boolean.TRUE);
        return this.update(new PrizeDrawActivityPoolSettleLog(),wrapper);
    }

    public Integer getCountByLinkIdAndOrderId(Long linkId, Long orderId) {
        LambdaQueryWrapper<PrizeDrawActivityPoolSettleLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PrizeDrawActivityPoolSettleLog::getLinkId, linkId);
        wrapper.eq(PrizeDrawActivityPoolSettleLog::getOrderId, orderId);
        return this.count(wrapper);
    }
}